package csm.api.search;

import java.util.List;

import org.jdom.Element;

import csm.common.xml.XmlDocument;

class SearchTest
{

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception
    {
        // 검색요청정보를 생성한다
        // 보통은 웹폼을 통해 전달받은 파라메터를 이용해서 생성한다.
        SearchRequest srchRequest = new SearchRequest();
        srchRequest.setApiKey("900d815a1ccfdf1ad6a00a7130a52abd");
        srchRequest.setSearchData("");
        srchRequest.setDefaultUrlParam("new");


        // 검색자를 획득한다.
        ISearchProvider sp = SearchProviderFactory.getSearchProvider(SearchProviderType.Naver);
        sp.setRequest(srchRequest);
        ISearchResult result = sp.search();

        System.out.println(result.getRawString());

        XmlDocument doc = new XmlDocument(result.getRawString());

        System.out.println(doc.selectSingleNodeText("/error"));

        List<Element> lst = doc.selectNodes("/error");

        for(Element el : lst)
        {
            System.out.println(el.getName() + ":" + el.getText());

            System.out.println(el.getChildren().size());
        }

    }

}
